unit UFormPesquisa;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RXDBCtrl,ToolEdit, StdCtrls, Buttons, ExtCtrls, Db, DBTables, Grids, DBGrids;

type
  TFormPesquisa = class(TForm)
    Panel2: TPanel;
    BtnConsultar: TBitBtn;
    BtnLimpar: TBitBtn;
    BtnImprimir: TBitBtn;
    BtnSelecionar: TBitBtn;
    BtnFechar: TBitBtn;
    Panel1: TPanel;
    QPesquisa: TQuery;
    DSPesquisa: TDataSource;
    DBGrid1: TDBGrid;
    Panel3: TPanel;
    LRegistros: TLabel;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnConsultarClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    Comp :tcomponent;
    procedure ControlChange(Sender: TObject);
  public
    { Public declarations }
  end;

var
  FormPesquisa:TFormPesquisa;

implementation

uses UGeral;



{$R *.DFM}

procedure TFormPesquisa.BtnFecharClick(Sender: TObject);
begin
 self.close;
end;

procedure TFormPesquisa.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 try
  QPesquisa.Close;
  Self.Release;
 except
  on e: Exception do
   begin
    ShowMessage(e.Message);
   end;
 end;
end;

procedure TFormPesquisa.ControlChange(Sender : TObject);
begin
// marcacampo(Self,Comp,ActiveControl,clWindow,clTeal,clMenu);
// marcacampo(Self,Comp,ActiveControl,clWindow,clMoneyGreen,clMenu);
end;

procedure TFormPesquisa.FormCreate(Sender: TObject);
var
 i :Integer;
begin
 Screen.OnActiveControlChange := ControlChange;
 Self.Position:=poMainFormCenter;
 Self.PrintScale:=poProportional;
 BtnImprimir.Enabled:=false;
 BtnSelecionar.Enabled:=false;
 QPesquisa.Close;
 for i:=0 to ComponentCount - 1 do
  begin
   if Components[i] is TDateEdit then
    TDateEdit(Components[i]).EditMask := MascaraData2;
  end;

end;

procedure TFormPesquisa.FormDestroy(Sender: TObject);
begin
  Screen.OnActiveControlChange := nil;
end;

procedure TFormPesquisa.BtnConsultarClick(Sender: TObject);
begin
  DSPesquisa.Enabled    := true;
  BtnImprimir.Enabled   := DSPesquisa.DataSet.RecordCount <> 0;
  BtnSelecionar.Enabled := (DSPesquisa.DataSet.RecordCount <> 0 )and (BtnSelecionar.Tag = 0) ;
  LRegistros.Caption    := 'Registros Encontrado(s) : ' + IntToStr(DSPesquisa.DataSet.RecordCount);

end;

procedure TFormPesquisa.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key = #13 then
 SelectNext(ActiveControl,true,true);

end;

procedure TFormPesquisa.FormActivate(Sender: TObject);
begin
 if (Self.Height > 400) and (Screen.Height <=600) then
  //Self.Top:=20;
end;

end.
